from pygame import mouse as pm
from pygame import init , display , mouse , time , image , key , event
from lib.res.glo import SRC , COLOR
from res.config import win_size , fps , game_name
from pygame.constants import QUIT
from sys import exit

init ( )
screen = display.set_mode ( win_size )
mouse.set_visible ( False )
display.set_caption ( game_name )
Clock = time.Clock ( )
isrunning = True
scenes = list ( )
mouse = image.load ( SRC [ 'mouse' ] )


class ZScreen ( object ) :
    def __init__ ( self ) :
        super ( ZScreen , self ).__init__ ( )

    def _add ( self , *Scene ) :
        for scene in Scene :
            scenes.append ( scene )

    def run ( self ) :
        while isrunning :
            screen.fill ( COLOR [ 'font' ] [ 'color' ] [ 0 ] )
            Clock.tick ( fps )
            keys = key.get_pressed ( )
            mouse_pos = pm.get_pos ( )
            mouse_key = pm.get_pressed ( )
            if len ( scenes ) :
                for x in scenes :
                    if x._running :
                        x.draw ( )
                for e in event.get ( ) :
                    if e.type == QUIT :
                        exit ( )
                    for x in scenes :
                        if x._running :
                            x.update ( e , mouse_pos , mouse_key )
                self._draw_mouse ( )
            display.update ( )

    def _draw_mouse ( self ) :
        screen.blit ( mouse , pm.get_pos ( ) )
